﻿using System;
using System.Web;

namespace CMS.Core {
	public class Admin {
		/// <summary>
		/// 登录验证
		/// </summary>
		/// <param name="loginId"></param>
		/// <param name="password"></param>
		/// <returns>验证成功, 返回对应的用户实体</returns>
		public static bool Validate(string loginId, string password) {
			Model.Admin model = new Model.Admin();
			model.LoginID = loginId;
			model.Password = Common.DesEncrypt.Encrypt(password);

			model = new Dao.Admin().Validate(model);

			Entity = model;

			return model != null;
		}

		/// <summary>
		/// 当前成功登录的用户的实体
		/// </summary>
		public static Model.Admin Entity {
			get {
				return HttpContext.Current.Session["Admin.Model"] as Model.Admin;
			}
			set {
				HttpContext.Current.Session.Clear();
				HttpContext.Current.Session.Add("Admin.Model", value);
			}
		}

		/// <summary>
		/// 当前成功登录的用户名
		/// </summary>
		public static string Name {
			get {
				if (Entity != null)
					return Entity.Name;
				else
					return string.Empty;
			}
		}
	}
}
